<?php //print_r($view);die;?>
<script type="text/javascript">
    function showTheWinner(){
        var d = jQuery("#chosen_day").val();
        jQuery.post("?action=getwinner", {day:d}, function(r){
           jQuery.blockUI({
              message:r 
           });
        });
    }
    
    function showCSVData()
    {
        var day = jQuery("#chosen_day").val();
        var url = "?action=exportcsv&day=" + day;
        window.open(url, '_blank');
        window.focus();
    }
</script>

<div class="row-fluid no-margin">
	<div class="span12">
		<ul class="quicktasks">
			<li>
				<a href="javascript:showTheWinner();"> <img
						src="<?php echo $view->layoutUrl;?>/assets/img/icons/essen/32/user.png"
						alt=""> <span>Pick Winner</span>
				</a>
			</li>			
                        <li>
				<a href="javascript:showCSVData();"> <img
						src="<?php echo $view->layoutUrl;?>/assets/img/icons/essen/32/billing.png"
						alt=""> <span>Export to CSV</span>
				</a>
			</li>
		</ul>
            <form style="float: right; margin-top: -66px;" class="form-horizontal" id="formfilter" method="get" action="?action=viewresults">
                <input type="hidden" name="action" value="<?php echo $view->action;?>" />
                <input type="hidden" name="p" value="1" />
                
                <div class="control-group" style="float:left;margin-right:5px;">
                        <label class="control-label" for="select">Date</label>
                        <div class="controls">
                                <select id="chosen_day" name="day">
                                        <option value="*">---- All ----</option>
                                        <?php for($j = 1;$j<=24;$j++){?>
                                        <option<?php if($view->day == $j){?> selected="selected" <?php } ?> value="<?php echo $j;?>" ><?php echo $j;?>. desember</option>
                                        <?php } ?>    
                                </select>
                        </div>
                </div>
                
                <button type="submit" class="btn btn-primary">Filter</button>
                
            </form>
	</div>
</div>
<div class="row-fluid">
	<div class="span12">
		<div class="box">
			<div class="box-head">
				<h3>Christmas Calendar Results</h3>
			</div>
			<div class="box-content box-nomargin">
				<div class="alert alert-info">
				Christmas Calendar Results					
				</div>
				<table
					class='table table-striped table-media table-bordered<?php if($view->total <= 2000) { ?> dataTable<?php } ?>'>
					<thead>
						<tr>	
                                                        <th>ID</th>
							<th>Date</th>
							<th>Name</th>
							<th>Email</th>
							<th>Question</th>
							<th>Answer</th>
							<th>Submited time</th>
						</tr>
					</thead>
					<tbody>
                                            
                                        <?php foreach($view->comments as $i => $u) { ?>
                                        <tr<?php if($i % 2 != 0){?> style='background-color:#F6F6F6;'<?php } ?>>
                                            <td><?php echo $u['answer_id'];?></td>
                                            <td><?php echo $u['day_num'];?>. desember</td>
                                            <td><?php echo $u['name'];?></td>
                                            <td><?php echo $u['email'];?></td>
                                            <td><?php echo $u['question'];?></td>
                                            <td>
                                            <?php 
                                            if($u['answer'] != 0){
                                                echo $u['answer_' . $u['answer']];
                                            } else {
                                                echo $u['custom_answer'];
                                            }
                                            ?>
                                            </td>
                                            <td><?php echo date("d.m.Y H:i", $u['update_time']);?></td>
                                        </tr>
                                        <?php } ?>                                            					
					</tbody>
				</table>
                            
                            <?php if($view->total > 2000) { ?>
                            <div class="dataTables_info" id="DataTables_Table_0_info">
                                Showing page <?php echo $view->currentPage;?>/<?php echo $view->numOfPages;?>
                            </div>
                            
                            <div class="dataTables_paginate paging_bootstrap pagination">
                                <ul>
                                    <li class="prev<?php if($view->prePage == $view->currentPage){ ?> disabled<?php } ?>">
                                        <a href="?action=viewresults&p=<?php echo $view->prePage;?>&day=<?php echo $view->day;?>">← Previous</a>
                                    </li>
                                    <?php for($i = $view->startpage; $i< $view->endpage;$i++) {?>
                                    <li<?php if($i == $view->currentPage){?> class="active"<?php } ?>>
                                        <a href="?action=viewresults&p=<?php echo $i;?>&day=<?php echo $view->day;?>"><?php echo $i;?></a>
                                    </li>
                                    <?php } ?>                                    
                                    <li class="next<?php if($view->nextPage == $view->currentPage){ ?> disabled<?php } ?>">
                                        <a href="?action=viewresults&p=<?php echo $view->nextPage;?>&day=<?php echo $view->day;?>">Next → </a>
                                    </li>
                                </ul>
                            </div>
                            <?php } ?>
                            
			</div>
		</div>
	</div>
</div>
